//package com.yfeng.security.interceptor;
//
//import org.springframework.security.intercept.web.FilterInvocationDefinitionSource;
//import org.springframework.security.intercept.web.FilterInvocation;
//import org.springframework.security.ConfigAttributeDefinition;
//import org.springframework.security.ConfigAttributeEditor;
//import org.springframework.security.util.UrlMatcher;
//import org.springframework.security.util.AntUrlPathMatcher;
//
//import java.util.Collection;
//import java.util.Map;
//
//
//import javax.servlet.ServletContext;
//
///**
// * Created by IntelliJ IDEA.
// * User: raoqn
// * Date: 2009-2-6 15:32:07
// */
//public class SecureResourceFilter implements FilterInvocationDefinitionSource {
//    private UrlMatcher urlMatcher = new AntUrlPathMatcher();
//
//    public ConfigAttributeDefinition getAttributes(Object filter) throws IllegalArgumentException {
//        FilterInvocation filterInvocation = (FilterInvocation) filter;
//        String requestURI = filterInvocation.getRequestUrl();
//
//        String grantedAuthorities = null;
//
//        Map m = this.getUrlAuthorities(filterInvocation);
//
//        for (Object o : m.keySet()) {
//            if (urlMatcher.pathMatchesUrl(urlMatcher.compile(o.toString()), requestURI)) {
//                grantedAuthorities = (String) m.get(o);
//                break;
//            }
//        }
//
//        if (grantedAuthorities != null) {
//            ConfigAttributeEditor configAttrEditor = new ConfigAttributeEditor();
//            configAttrEditor.setAsText(grantedAuthorities);
//            return (ConfigAttributeDefinition) configAttrEditor.getValue();
//        }
//        return null;  //To change body of implemented methods use File | Settings | File Templates.
//    }
//
//    public Collection getConfigAttributeDefinitions() {
//        return null;  //To change body of implemented methods use File | Settings | File Templates.
//    }
//
//    public boolean supports(Class aClass) {
//        return true;  //To change body of implemented methods use File | Settings | File Templates.
//    }
//
//    @SuppressWarnings("unchecked")
//    private Map getUrlAuthorities(FilterInvocation filterInvocation) {
//        ServletContext servletContext = filterInvocation.getHttpRequest().getSession().getServletContext();
//        return (Map) servletContext.getAttribute("urlAuthorities");
//    }
//}
